package com.newer.his.BasicData.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.newer.his.common.entity.Role;
import com.newer.his.common.mapper.RoleMapper;

/**
 * 
 * 角色
 *
 */

@RestController
@RequestMapping("/role")
public class RoleController {
	@Autowired
	RoleMapper mapper;
	
	@GetMapping
	public List<Role> getAllRole(){
		return mapper.findAll();
	}
	
	@GetMapping("/{id}")
	public Role getRoleById(@PathVariable int id) {
		return mapper.findbyId(id);
		
	}
	
	

	 @PostMapping
	public Role addRole(Role role) {
		mapper.save(role);
		return role;
		
	}
	 @PutMapping("/{id}")
	public  void updateRole(@PathVariable int id,
			@RequestBody Role role) {
		 role.setId(id);
		mapper.update(role);
		
	}
	 @DeleteMapping("/{id}")
	public  void deleteRole(@PathVariable int id) {
		mapper.delete(id);
	
	

}
	
	
	
	
	

}
